<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    button.btn{
      position: fixed;
      right: 20px;
      bottom: 50px;
      display: none;
    }
  </style>
</head>
<body>
  <div id="app" style="height: 3000px;">
    商品价格
    <button style="margin-top: 300px" @click="isShow = !isShow">点击</button>
    <button class="btn" v-if="isShow" v-back-top="200">回到顶部</button>
  </div>
  <script src="./vue.js"></script>
  <script>
  
    Vue.directive('back-top',{
      inserted(el,binding){
        const top = binding.value;
        window.onscroll = function(){
          const sTop = document.documentElement.scrollTop||document.body.scrollTop;
          console.log(111)
          if(sTop>top){
            el.style.display="block";
          }else{
            el.style.display="none";
          }
        }
        el.onclick = function(){
          window.scrollTo(0,0)
        }
      },
      unbind(){
        console.log('解绑了');
        window.onscroll = null;
      }
    })
  
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      },
      filters: {
        capticalSize:(v)=>{
          return v[0].toUpperCase()+v.substr(1)
        }
      }
    })
  </script>
</body>
</html>